// gui/GuiSelectableText.cpp

#include "GuiSelectableText.h"

TypeId GUI::GuiSelectableText::s_TypeId = "GuiSelectableText";

using namespace GUI;

void GuiSelectableText::UpdateHotSpot()
{
	const EGuiTextHAlign eHAlignment = m_TextItem.GetHAlign();
	const EGuiTextVAlign eVAlignment = m_TextItem.GetVAlign();

	float fLeft = 0.0f, fRight = 0.0f;
	float fTop = 0.0f, fBottom = 0.0f;

	switch (eHAlignment)
	{
	case E_GUITEXTHALIGN_LEFT:
		fLeft = 0.0f;
		fRight = m_TextItem.GetTextWidth();
		break;
	case E_GUITEXTVALIGN_CENTRE:
		{
			const float fHalfWidth = m_TextItem.GetTextWidth() * 0.5f;
			fLeft = -fHalfWidth;
			fRight = fHalfWidth;
		}
		break;
	case E_GUITEXTHALIGN_RIGHT:
		fLeft = -m_TextItem.GetTextWidth();
		fRight = 0.0f;
	default: // [NOTE] : Error
		break; 
	}

	switch (eVAlignment)
	{
	case E_GUITEXTVALIGN_TOP:
		fTop = 0.0f;
		fBottom = m_TextItem.GetTextHeight();
		break;
	case E_GUITEXTVALIGN_CENTRE:
		{
			const float fHalfHeight = m_TextItem.GetTextHeight() * 0.5f;
			fTop = fHalfHeight;
			fBottom = -fHalfHeight;
		}
		break;

	case E_GUITEXTVALIGN_BOTTOM:
	case E_GUITEXTVALIGN_BASELINE:
		fTop = m_TextItem.GetTextHeight();
		fBottom = 0.0f;
		break;
	default: // [NOTE] : Error
		break;
	}

	m_HotSpot.SetFrame( &GetFrame() );
	m_HotSpot.SetRect( fLeft, fTop, fRight, fBottom );
}